package ThreadTest;
/*
合理得终止一个线程
    打一个布尔标记
 */
public class ThreadTest7 {
    public static void main(String[] args) {
        MyThread7 myThread7= new MyThread7();
        Thread t = new Thread(myThread7);
        t.setName("t");
        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //改变run属性的值，合理终止线程
        myThread7.run = false;
        //线程优先级最低为1，默认为5，最高为10
        t.setPriority(6); //设置优先级
        System.out.println(t.getPriority()); //获取线程优先级
        //优先级高的，相对抢占的时间片更多一点
    }
}
class MyThread7 implements Runnable{
    boolean run = true;
    @Override
    public void run() {
        for(int i = 0; i < 10; i++){
            if(run){
                System.out.println(Thread.currentThread().getName()+"-->"+i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }else {
                return;
            }
        }
    }
}
